package Operations;

import java.util.Map;


public class AssignPrimitive extends Operation{
	private final Class<?> clz;
	private final String ref;
	private final String value;
	public AssignPrimitive(Class<?> clz,String ref, String value) {
		this.clz=clz;
		this.ref = ref;
		this.value = value;
	}

	public static AssignPrimitive generate(Class<?> clz,String cName, Map<String, String[]>  refFactory){
	//	String cName=c.getName();
		String[] refrences=refFactory.get(cName);
		int randRef=ValuesGenerator.getRandomInt(refrences.length);
		String ref=refrences[randRef];
		String value=ValuesGenerator.buildValue(cName);
		
		return new AssignPrimitive(clz,ref,value);
	}
	@Override
	public Operation clone() {
		final AssignPrimitive clone = new AssignPrimitive(clz,ref, value);

		return clone;
	}
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(ref);
		if(value == null)  sb.append(" = null".toString() );
		else	sb.append(" = " + value);
		
		return sb.toString();
	}


}
